package com.hrt.manage.menus.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.Cash;
import com.hrt.bean.ViewResource;
import com.hrt.bean.ViewResourceScopes;
import com.hrt.manage.menus.dao.ViewResourceDao;
import com.hrt.manage.menus.service.ViewResourceService;

@Service
public class ViewResourceServiceImpl implements ViewResourceService {

	@Autowired
	private ViewResourceDao dao;

	@Override
	public List<ViewResource> listManageMenuns(Integer scope) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Long totalCount(Integer scope) {

		Long total = 0l;

		if (scope == null) {

			total = dao.totalCount();

		} else if (scope.intValue() == ViewResourceScopes.WEB_RESOURCE
				|| scope.intValue() == ViewResourceScopes.MANAGE_RESOURCE) {

			total = dao.totalCount(scope);
		} else {

			total = dao.totalCount();
		}

		return total;
	}

	/***
	 * 条件查询
	 */
	@Override
	public List<ViewResource> queryByPage(Map<String, Object> conditions,
			int pageIndex, int pageSize) {
		List<ViewResource> resultList = new ArrayList<ViewResource>();
		resultList = dao.queryByPage(pageIndex, pageSize);
		return resultList;
	}

	/**
	 * 
	 */
	@Override
	public List<ViewResource> queryByPage(Integer scope, int pageIndex,
			int pageSize) {
		List<ViewResource> resultList = new ArrayList<ViewResource>();
		if (scope == null) {

			resultList = dao.queryByPage(pageIndex, pageSize);

		} else if (scope.intValue() == ViewResourceScopes.WEB_RESOURCE
				|| scope.intValue() == ViewResourceScopes.MANAGE_RESOURCE) {

			resultList = dao.queryByPage(scope, pageIndex, pageSize);
		} else {

			resultList = dao.queryByPage(pageIndex, pageSize);
		}

		return resultList;
	}

	@Override
	public List<ViewResource> queryByPage(int pageIndex, int pageSize) {
		// TODO Auto-generated method stub
		List<ViewResource> resultList = new ArrayList<ViewResource>();
		resultList = dao.queryByPage(pageIndex, pageSize);
		return resultList;
	}

	@Override
	public Timestamp getDate() {
		// TODO Auto-generated method stub
		return dao.getDate();
	}

	@Override
	public ViewResource getViewResourceById(Long id) {
		// TODO Auto-generated method stub
		return dao.getViewResourceById(id);
	}

	@Override
	@Transactional
	public void updateRole(ViewResource viewResource) {
		// TODO Auto-generated method stub
		dao.updateEntity(viewResource);
	}

	@Override
	@Transactional
	public Long saveMenun(ViewResource viewResource) {
		// TODO Auto-generated method stub
		return dao.saveEntity(viewResource);
	}

	@Override
	public void  deleteById(Long[] idArr) {
		// TODO Auto-generated method stub
		List<Long> delArr = new ArrayList<Long>();
		if (idArr != null && idArr.length > 0) {
			for (Long id : idArr) {
				ViewResource c = dao.getById(id);
				c.setIsdelete(new Integer(1));
				dao.updateEntity(c);
				delArr.add(id);
			}
		}
		
	}

}
